//
//  SettingsViewController.m
//  BaChat
//
//  Created by 刘洋 on 16/6/14.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "SettingsViewController.h"
#import "LoginAndRegisterViewController.h"
#import "AppDelegate.h"
@interface SettingsViewController ()

@end

@implementation SettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"退出登录" style:UIBarButtonItemStylePlain target:self action:@selector(loginButton)];
    
    
    
    
    // Do any additional setup after loading the view.
}


-(void)loginButton{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"退出后不会删除任何历史数据,下次登录依然可以使用本账号." preferredStyle:UIAlertControllerStyleActionSheet];
    [alert addAction:[UIAlertAction actionWithTitle:@"退出登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//退出登录
        [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
            if (!error) {
                NSLog(@"退出成功");
               
                
            }
            
        } onQueue:dispatch_get_main_queue()];
        
//跳转回登录页面
        LoginAndRegisterViewController *loginVC = [[LoginAndRegisterViewController alloc]init];
//改为不是自动登录
        [[EaseMob sharedInstance].chatManager setIsAutoLoginEnabled:NO];
        [self presentViewController:loginVC animated:YES completion:nil];
        [loginVC release];

//将添加好的单例清空
        [[AppDelegate shareFriendDic] removeAllObjects];
     
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
